import 'package:flutter/material.dart';
import 'package:sweet_app/buttons/simple_round_button.dart';

class LoadingButton extends StatelessWidget {

  final Color backgroundColor;
  final Text buttonText;
  final Color textColor;
  final VoidCallback onPressed;
  final bool loading;

  LoadingButton({
    this.loading,
    this.backgroundColor,
    this.buttonText,
    this.textColor,
    @required this.onPressed
  });


  @override
  Widget build(BuildContext context) {
    return SimpleRoundButton(
      onPressed: () {
        if(!loading) {
          onPressed();
        } else  {
          return;
        }
      },
      backgroundColor: !loading ? backgroundColor : backgroundColor.withOpacity(0.6),
      buttonText: Row(
        children: <Widget>[
          Offstage(
            offstage: !loading,
            child:  SizedBox(
              width: 15.0,
              height: 15.0,
              child: CircularProgressIndicator(
                strokeWidth: 2.0,
                valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
              ),
            ),
          ),
          const SizedBox(width: 5.0),
          buttonText,
        ],
      ),
      textColor: textColor,
    );
  }

}
